home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / skipandgouls.swf / scripts / __Packages / Controller.as next >
Text File  |  2007-10-01  |  8KB  |  220 lines

  1. class Controller
  2. {
  3.    static var QUALITY_LOW = 0;
  4.    static var QUALITY_MEDIUM = 1;
  5.    static var QUALITY_HI = 2;
  6.    function Controller(l_mcTimeline)
  7.    {
  8.       _global.C = this;
  9.       this.mcContainer = l_mcTimeline;
  10.       this.mcContainer.stop();
  11.       this.mcContainer._y = 0;
  12.       mx.transitions.OnEnterFrameBeacon.init();
  13.       this.oEnterFrameListener = new Object();
  14.       this.oEnterFrameListener.onEnterFrame = mx.utils.Delegate.create(this,this.update);
  15.       MovieClip.addListener(this.oEnterFrameListener);
  16.       sarbakan.sound.SoundManager.init(l_mcTimeline);
  17.       this.setQuality();
  18.       this.oPackaging = new Packaging(l_mcTimeline.mcPackaging);
  19.       this.bRestartGame = false;
  20.       this.bEndGame = false;
  21.       this.bEndLevelPart = false;
  22.       this.nLevelPart = 1;
  23.       this.nLevelPartScore = 0;
  24.       this.nLevelPartMinutes = 0;
  25.       this.nLevelPartSeconds = 0;
  26.       this.oUnlockedCodes = SharedObject.getLocal("sbghouls_codes");
  27.    }
  28.    function initGame(l_bSameLevel, l_bNextPart)
  29.    {
  30.       this.mcContainer.gotoAndStop("game");
  31.       sarbakan.visual.PauseManager.reset();
  32.       this.resetElementsID();
  33.       if(!l_bSameLevel)
  34.       {
  35.          if(l_bNextPart)
  36.          {
  37.             this.nLevelPart = this.nLevelPart + 1;
  38.             this.nLevelPartScore = this.oHUD.nScore;
  39.             this.nLevelPartMinutes = this.oHUD.nMinutes;
  40.             this.nLevelPartSeconds = this.oHUD.nSeconds;
  41.          }
  42.          if(this.nLevelPart < 4)
  43.          {
  44.             this.oModel = new maze.MazeModel(maze.MazeData.DIFFICULTY_SETTING[this.nDifficultyLevel].width,maze.MazeData.DIFFICULTY_SETTING[this.nDifficultyLevel]["height" + this.nLevelPart]);
  45.             this.oGenerator = new maze.MazeGenerator(this.oModel);
  46.             this.oGenerator.generate(false);
  47.          }
  48.          else
  49.          {
  50.             this.oModel = new maze.MazeModel(maze.MazeData.BONUS_WIDTH,maze.MazeData.BONUS_HEIGHT);
  51.             this.oGenerator = new maze.MazeGenerator(this.oModel);
  52.             this.oGenerator.generate(true);
  53.          }
  54.       }
  55.       this.bSamePart = l_bSameLevel;
  56.       this.oGameView = new sarbakan.visual.layer.LayerManager(this.oModel.nWidth * maze.MazeData.VIEW_TILE_WIDTH,this.oModel.nHeight * maze.MazeData.VIEW_TILE_HEIGHT,600,300);
  57.       this.oCam = this.oGameView.getCamera();
  58.       this.oLayerFloor = new sarbakan.visual.layer.Layer(this.mcContainer.mcGame.mcFloor,new sarbakan.visual.activation.GridActivation());
  59.       this.oGameView.addLayer(this.oLayerFloor,1,1);
  60.       this.oLayerGame = new sarbakan.visual.layer.Layer(this.mcContainer.mcGame.mcMaze,new sarbakan.visual.activation.GridActivation());
  61.       this.oGameView.addLayer(this.oLayerGame,1,1);
  62.       this.oLayerGame.addCollisionMap(new sarbakan.visual.layer.CollisionMap("floor",this.oLayerGame,12632256));
  63.       this.oLayerGame.oCollisionMaps.floor.setNewSource(this.mcContainer.mcGame.mcFloor);
  64.       this.oLayerGame.oCollisionMaps.floor.show(100);
  65.       this.oLayerBg = new sarbakan.visual.layer.Layer(this.mcContainer.mcGame.mcBg,new sarbakan.visual.activation.NoActivation());
  66.       this.oGameView.addLayer(this.oLayerBg,1,1);
  67.       this.oSpongeBob = new characters.SpongeBob(this.mcContainer.mcGame.mcMaze.mcSpongeBob);
  68.       this.oLayerGame.addDynamicElement(this.oSpongeBob);
  69.       this.oCam.lockOn(mx.utils.Delegate.create(this.oSpongeBob,this.oSpongeBob.getCoord),true);
  70.       if(this.oUnlockedCodes.data.SYRUP_WATER)
  71.       {
  72.          if(this.sLastWaterType == "water")
  73.          {
  74.             this.oWater.mc.removeMovieClip();
  75.          }
  76.          this.mcContainer.mcGame.mcMaze.gotoAndStop("syrup");
  77.          this.sLastWaterType = "syrup";
  78.       }
  79.       else
  80.       {
  81.          this.mcContainer.mcGame.mcMaze.gotoAndStop("water");
  82.          this.sLastWaterType = "water";
  83.       }
  84.       this.oWater = new maze.elements.Water(this.mcContainer.mcGame.mcMaze.mcWater);
  85.       this.oLayerGame.addDynamicElement(this.oWater);
  86.       this.oMazeView = new maze.MazeView(this.oLayerGame,this.oModel);
  87.       this.oMazeView.render();
  88.       this.oHUD = new HUD(this.mcContainer.mcHUD);
  89.       this.oHUD.showGetOut();
  90.       this.oHUD.setScore(this.nLevelPartScore);
  91.       this.oHUD.setTimer(this.nLevelPartMinutes,this.nLevelPartSeconds);
  92.       this.oAmbiance = sarbakan.sound.SoundManager.play("ambiance",maze.MazeData.VOLUME_AMBIANCE,99999,true);
  93.       this.oGameView.update();
  94.    }
  95.    function destroyGame()
  96.    {
  97.       sarbakan.sound.SoundManager.stop(this.oAmbiance);
  98.       this.oGameView.destroy();
  99.       delete this.oGameView;
  100.    }
  101.    function resetElementsID()
  102.    {
  103.       sarbakan.visual.element.BaseElement.resetID();
  104.       sarbakan.visual.element.BaseElement.resetID();
  105.       sarbakan.visual.element.BaseElement.resetID();
  106.       sarbakan.visual.element.BaseElement.resetID();
  107.       sarbakan.visual.element.BaseElement.resetID();
  108.    }
  109.    function endLevelPart()
  110.    {
  111.       this.bEndLevelPart = true;
  112.    }
  113.    function endGame(l_bWin)
  114.    {
  115.       this.nLevelPart = 1;
  116.       this.nLevelPartScore = 0;
  117.       this.nLevelPartMinutes = 0;
  118.       this.nLevelPartSeconds = 0;
  119.       this.oHUD.resetLife();
  120.       this.bEndGame = true;
  121.       if(l_bWin)
  122.       {
  123.          _global.C.oPackaging.goto("endGood" + this.nDifficultyLevel);
  124.       }
  125.       else
  126.       {
  127.          _global.C.oPackaging.goto("endBad");
  128.       }
  129.    }
  130.    function restartGame()
  131.    {
  132.       this.bRestartGame = true;
  133.       this.bRestarting = true;
  134.    }
  135.    function restartFadeMiddle()
  136.    {
  137.       this.destroyGame();
  138.       if(this.nLevelPart <= 3)
  139.       {
  140.          if(this.bRestarting)
  141.          {
  142.             this.initGame(true,false);
  143.             this.bRestarting = false;
  144.          }
  145.          else
  146.          {
  147.             this.initGame(false,true);
  148.          }
  149.       }
  150.    }
  151.    function restartFadeEnd()
  152.    {
  153.       this.mcContainer.mcFade.gotoAndPlay("disabled");
  154.    }
  155.    function setDifficulty(l_nDifficultyLevel)
  156.    {
  157.       this.nDifficultyLevel = l_nDifficultyLevel;
  158.    }
  159.    function togglePause()
  160.    {
  161.       if(sarbakan.visual.PauseManager.bPaused)
  162.       {
  163.          sarbakan.sound.SoundManager.fade(_global.C.oPackaging.oMusic,sarbakan.sound.SoundManager.FADE_VOLUME,maze.MazeData.VOLUME_MUSIC,15);
  164.       }
  165.       else
  166.       {
  167.          sarbakan.sound.SoundManager.fade(_global.C.oPackaging.oMusic,sarbakan.sound.SoundManager.FADE_VOLUME,maze.MazeData.VOLUME_MUSIC / 3,15);
  168.       }
  169.       this.oGameView.togglePause();
  170.    }
  171.    function unlockCode(l_sCodeID)
  172.    {
  173.       if(l_sCodeID == "RESET")
  174.       {
  175.          for(var _loc2_ in this.oUnlockedCodes.data)
  176.          {
  177.             this.oUnlockedCodes.data[_loc2_] = false;
  178.          }
  179.       }
  180.       else
  181.       {
  182.          this.oUnlockedCodes.data[l_sCodeID] = true;
  183.       }
  184.    }
  185.    function update()
  186.    {
  187.       if(this.bRestartGame || this.bEndLevelPart)
  188.       {
  189.          this.mcContainer.mcFade.gotoAndPlay("fade");
  190.          this.bRestartGame = false;
  191.          this.bEndLevelPart = false;
  192.       }
  193.       if(this.bEndGame)
  194.       {
  195.          this.destroyGame();
  196.          this.bEndGame = false;
  197.       }
  198.       if(this.oGameView)
  199.       {
  200.          this.oGameView.update();
  201.          this.oHUD.update();
  202.       }
  203.       else
  204.       {
  205.          this.oPackaging.update();
  206.       }
  207.    }
  208.    function setQuality()
  209.    {
  210.       if(_global.PerformanceTestResult >= 20)
  211.       {
  212.          this.nQuality = Controller.QUALITY_MEDIUM;
  213.       }
  214.       else
  215.       {
  216.          this.nQuality = Controller.QUALITY_LOW;
  217.       }
  218.    }
  219. }
  220.